package shopping.demo.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import shopping.demo.entities.User;

import java.util.List;

@Repository
@Mapper
public interface UserDao {
    @Select("select userId,username,password,money,role from user")
    public List<User> findAll();

    @Select("select userId,username,password,money,role from user where userId=#{userId}")
    public User findByUserId(Long userId);

    @Update("update user set password=#{password} where userId=#{userId}")
    public int changePassword(Long userId, String password);

    @Update("update user set money=money-#{cost} where userId=#{userId}")
    public int moneyDown(Long userId, Integer cost);

    @Update({"update user set money=money+100 where userId=#{userId}"})
    public int moneyUp(Long userId);

    @Delete("delete from user where userId=#{userId}")
    public int deleteByUserId(Long userId);

    @Insert("insert into user(userId,username,password,money,role) values(#{userId},#{username},#{password},#{money},'consumer')")
    public int insertUser(Long userId, String username, String password, Integer money);
}
